Implementing a single input neuron


In [38]:
import tensorflow as tf
import matplotlib.pyplot as plt

In [39]:
%matplotlib inline

In [40]:
interactive_sesssion=tf.InteractiveSession()

In [41]:
input_value = tf.constant(0.5,name="input_value")

In [42]:
weight = tf.Variable(1.0,name="weight")

In [43]:
expected_output = tf.constant(0.0,name="expected_output")

In [44]:
model = tf.multiply(input_value, weight,"model")

In [45]:
loss_function = (model - expected_output)**2

In [46]:
optim = tf.train.GradientDescentOptimizer(learning_rate=0.025)

In [47]:
train_step=optim.minimize(loss_function)

In [48]:
for value in [input_value,weight,expected_output,model,loss_function]:     
    tf.summary.scalar(value.op.name,value)

In [49]:
summaries = tf.summary.merge_all()

In [50]:
summary_writer = tf.summary.FileWriter('log_simple_stats',interactive_sesssion.graph)

In [51]:
init_op=tf.global_variables_initializer()

In [52]:
interactive_sesssion.run(init_op)

In [53]:
scatter_output_x=[]
scatter_output_y=[]

In [54]:
for i in range(500):
    interactive_sesssion.run(train_step)
    loss=interactive_sesssion.run(loss_function)
    w=interactive_sesssion.run(weight)
    print("loss is %f. weight is %f"%(loss,w))
    scatter_output_x.append(i)
    scatter_output_y.append(w)
    summary_writer.add_summary(interactive_sesssion.run(summaries),i)


loss is 0.243789. weight is 0.987500
loss is 0.237732. weight is 0.975156
loss is 0.231826. weight is 0.962967
loss is 0.226067. weight is 0.950930
loss is 0.220450. weight is 0.939043
loss is 0.214974. weight is 0.927305
loss is 0.209633. weight is 0.915714
loss is 0.204425. weight is 0.904267
loss is 0.199346. weight is 0.892964
loss is 0.194394. weight is 0.881802
loss is 0.189564. weight is 0.870779
loss is 0.184855. weight is 0.859895
loss is 0.180262. weight is 0.849146
loss is 0.175784. weight is 0.838532
loss is 0.171417. weight is 0.828050
loss is 0.167158. weight is 0.817699
loss is 0.163005. weight is 0.807478
loss is 0.158956. weight is 0.797385
loss is 0.155006. weight is 0.787417
loss is 0.151156. weight is 0.777575
loss is 0.147400. weight is 0.767855
loss is 0.143738. weight is 0.758257
loss is 0.140167. weight is 0.748779
loss is 0.136685. weight is 0.739419
loss is 0.133289. weight is 0.730176
loss is 0.129978. weight is 0.721049
loss is 0.126749. weight is 0.712036
loss is 0.123600. weight is 0.703135
loss is 0.120529. weight is 0.694346
loss is 0.117535. weight is 0.685667
loss is 0.114615. weight is 0.677096
loss is 0.111767. weight is 0.668632
loss is 0.108991. weight is 0.660274
loss is 0.106283. weight is 0.652021
loss is 0.103642. weight is 0.643871
loss is 0.101067. weight is 0.635822
loss is 0.098557. weight is 0.627874
loss is 0.096108. weight is 0.620026
loss is 0.093720. weight is 0.612276
loss is 0.091392. weight is 0.604622
loss is 0.089122. weight is 0.597064
loss is 0.086907. weight is 0.589601
loss is 0.084748. weight is 0.582231
loss is 0.082643. weight is 0.574953
loss is 0.080590. weight is 0.567766
loss is 0.078588. weight is 0.560669
loss is 0.076635. weight is 0.553661
loss is 0.074731. weight is 0.546740
loss is 0.072875. weight is 0.539906
loss is 0.071064. weight is 0.533157
loss is 0.069299. weight is 0.526493
loss is 0.067577. weight is 0.519911
loss is 0.065898. weight is 0.513413
loss is 0.064261. weight is 0.506995
loss is 0.062664. weight is 0.500657
loss is 0.061108. weight is 0.494399
loss is 0.059590. weight is 0.488219
loss is 0.058109. weight is 0.482117
loss is 0.056665. weight is 0.476090
loss is 0.055258. weight is 0.470139
loss is 0.053885. weight is 0.464262
loss is 0.052546. weight is 0.458459
loss is 0.051241. weight is 0.452728
loss is 0.049968. weight is 0.447069
loss is 0.048726. weight is 0.441481
loss is 0.047516. weight is 0.435962
loss is 0.046335. weight is 0.430513
loss is 0.045184. weight is 0.425131
loss is 0.044062. weight is 0.419817
loss is 0.042967. weight is 0.414569
loss is 0.041899. weight is 0.409387
loss is 0.040859. weight is 0.404270
loss is 0.039843. weight is 0.399217
loss is 0.038854. weight is 0.394226
loss is 0.037888. weight is 0.389299
loss is 0.036947. weight is 0.384432
loss is 0.036029. weight is 0.379627
loss is 0.035134. weight is 0.374882
loss is 0.034261. weight is 0.370196
loss is 0.033410. weight is 0.365568
loss is 0.032580. weight is 0.360999
loss is 0.031771. weight is 0.356486
loss is 0.030981. weight is 0.352030
loss is 0.030212. weight is 0.347630
loss is 0.029461. weight is 0.343284
loss is 0.028729. weight is 0.338993
loss is 0.028015. weight is 0.334756
loss is 0.027319. weight is 0.330571
loss is 0.026641. weight is 0.326439
loss is 0.025979. weight is 0.322359
loss is 0.025333. weight is 0.318329
loss is 0.024704. weight is 0.314350
loss is 0.024090. weight is 0.310421
loss is 0.023492. weight is 0.306540
loss is 0.022908. weight is 0.302709
loss is 0.022339. weight is 0.298925
loss is 0.021784. weight is 0.295188
loss is 0.021243. weight is 0.291498
loss is 0.020715. weight is 0.287855
loss is 0.020200. weight is 0.284257
loss is 0.019699. weight is 0.280703
loss is 0.019209. weight is 0.277194
loss is 0.018732. weight is 0.273730
loss is 0.018267. weight is 0.270308
loss is 0.017813. weight is 0.266929
loss is 0.017370. weight is 0.263593
loss is 0.016939. weight is 0.260298
loss is 0.016518. weight is 0.257044
loss is 0.016108. weight is 0.253831
loss is 0.015707. weight is 0.250658
loss is 0.015317. weight is 0.247525
loss is 0.014937. weight is 0.244431
loss is 0.014566. weight is 0.241375
loss is 0.014204. weight is 0.238358
loss is 0.013851. weight is 0.235379
loss is 0.013507. weight is 0.232436
loss is 0.013171. weight is 0.229531
loss is 0.012844. weight is 0.226662
loss is 0.012525. weight is 0.223829
loss is 0.012214. weight is 0.221031
loss is 0.011910. weight is 0.218268
loss is 0.011614. weight is 0.215539
loss is 0.011326. weight is 0.212845
loss is 0.011044. weight is 0.210185
loss is 0.010770. weight is 0.207557
loss is 0.010502. weight is 0.204963
loss is 0.010242. weight is 0.202401
loss is 0.009987. weight is 0.199871
loss is 0.009739. weight is 0.197372
loss is 0.009497. weight is 0.194905
loss is 0.009261. weight is 0.192469
loss is 0.009031. weight is 0.190063
loss is 0.008807. weight is 0.187687
loss is 0.008588. weight is 0.185341
loss is 0.008374. weight is 0.183024
loss is 0.008166. weight is 0.180737
loss is 0.007964. weight is 0.178477
loss is 0.007766. weight is 0.176246
loss is 0.007573. weight is 0.174043
loss is 0.007385. weight is 0.171868
loss is 0.007201. weight is 0.169720
loss is 0.007022. weight is 0.167598
loss is 0.006848. weight is 0.165503
loss is 0.006678. weight is 0.163434
loss is 0.006512. weight is 0.161391
loss is 0.006350. weight is 0.159374
loss is 0.006192. weight is 0.157382
loss is 0.006038. weight is 0.155414
loss is 0.005888. weight is 0.153472
loss is 0.005742. weight is 0.151553
loss is 0.005599. weight is 0.149659
loss is 0.005460. weight is 0.147788
loss is 0.005325. weight is 0.145941
loss is 0.005192. weight is 0.144117
loss is 0.005063. weight is 0.142315
loss is 0.004938. weight is 0.140536
loss is 0.004815. weight is 0.138780
loss is 0.004695. weight is 0.137045
loss is 0.004579. weight is 0.135332
loss is 0.004465. weight is 0.133640
loss is 0.004354. weight is 0.131970
loss is 0.004246. weight is 0.130320
loss is 0.004140. weight is 0.128691
loss is 0.004037. weight is 0.127082
loss is 0.003937. weight is 0.125494
loss is 0.003839. weight is 0.123925
loss is 0.003744. weight is 0.122376
loss is 0.003651. weight is 0.120846
loss is 0.003560. weight is 0.119336
loss is 0.003472. weight is 0.117844
loss is 0.003386. weight is 0.116371
loss is 0.003301. weight is 0.114916
loss is 0.003219. weight is 0.113480
loss is 0.003139. weight is 0.112061
loss is 0.003061. weight is 0.110661
loss is 0.002985. weight is 0.109277
loss is 0.002911. weight is 0.107911
loss is 0.002839. weight is 0.106563
loss is 0.002768. weight is 0.105231
loss is 0.002700. weight is 0.103915
loss is 0.002633. weight is 0.102616
loss is 0.002567. weight is 0.101333
loss is 0.002503. weight is 0.100067
loss is 0.002441. weight is 0.098816
loss is 0.002381. weight is 0.097581
loss is 0.002321. weight is 0.096361
loss is 0.002264. weight is 0.095157
loss is 0.002207. weight is 0.093967
loss is 0.002153. weight is 0.092792
loss is 0.002099. weight is 0.091633
loss is 0.002047. weight is 0.090487
loss is 0.001996. weight is 0.089356
loss is 0.001947. weight is 0.088239
loss is 0.001898. weight is 0.087136
loss is 0.001851. weight is 0.086047
loss is 0.001805. weight is 0.084971
loss is 0.001760. weight is 0.083909
loss is 0.001716. weight is 0.082860
loss is 0.001674. weight is 0.081825
loss is 0.001632. weight is 0.080802
loss is 0.001592. weight is 0.079792
loss is 0.001552. weight is 0.078794
loss is 0.001514. weight is 0.077809
loss is 0.001476. weight is 0.076837
loss is 0.001439. weight is 0.075876
loss is 0.001404. weight is 0.074928
loss is 0.001369. weight is 0.073991
loss is 0.001335. weight is 0.073066
loss is 0.001302. weight is 0.072153
loss is 0.001269. weight is 0.071251
loss is 0.001238. weight is 0.070361
loss is 0.001207. weight is 0.069481
loss is 0.001177. weight is 0.068613
loss is 0.001148. weight is 0.067755
loss is 0.001119. weight is 0.066908
loss is 0.001091. weight is 0.066072
loss is 0.001064. weight is 0.065246
loss is 0.001038. weight is 0.064430
loss is 0.001012. weight is 0.063625
loss is 0.000987. weight is 0.062829
loss is 0.000962. weight is 0.062044
loss is 0.000938. weight is 0.061268
loss is 0.000915. weight is 0.060503
loss is 0.000892. weight is 0.059746
loss is 0.000870. weight is 0.059000
loss is 0.000849. weight is 0.058262
loss is 0.000828. weight is 0.057534
loss is 0.000807. weight is 0.056815
loss is 0.000787. weight is 0.056104
loss is 0.000767. weight is 0.055403
loss is 0.000748. weight is 0.054711
loss is 0.000730. weight is 0.054027
loss is 0.000712. weight is 0.053351
loss is 0.000694. weight is 0.052684
loss is 0.000677. weight is 0.052026
loss is 0.000660. weight is 0.051376
loss is 0.000643. weight is 0.050733
loss is 0.000627. weight is 0.050099
loss is 0.000612. weight is 0.049473
loss is 0.000597. weight is 0.048855
loss is 0.000582. weight is 0.048244
loss is 0.000567. weight is 0.047641
loss is 0.000553. weight is 0.047045
loss is 0.000540. weight is 0.046457
loss is 0.000526. weight is 0.045877
loss is 0.000513. weight is 0.045303
loss is 0.000500. weight is 0.044737
loss is 0.000488. weight is 0.044178
loss is 0.000476. weight is 0.043625
loss is 0.000464. weight is 0.043080
loss is 0.000452. weight is 0.042542
loss is 0.000441. weight is 0.042010
loss is 0.000430. weight is 0.041485
loss is 0.000420. weight is 0.040966
loss is 0.000409. weight is 0.040454
loss is 0.000399. weight is 0.039948
loss is 0.000389. weight is 0.039449
loss is 0.000379. weight is 0.038956
loss is 0.000370. weight is 0.038469
loss is 0.000361. weight is 0.037988
loss is 0.000352. weight is 0.037513
loss is 0.000343. weight is 0.037044
loss is 0.000335. weight is 0.036581
loss is 0.000326. weight is 0.036124
loss is 0.000318. weight is 0.035672
loss is 0.000310. weight is 0.035227
loss is 0.000303. weight is 0.034786
loss is 0.000295. weight is 0.034351
loss is 0.000288. weight is 0.033922
loss is 0.000281. weight is 0.033498
loss is 0.000274. weight is 0.033079
loss is 0.000267. weight is 0.032666
loss is 0.000260. weight is 0.032257
loss is 0.000254. weight is 0.031854
loss is 0.000247. weight is 0.031456
loss is 0.000241. weight is 0.031063
loss is 0.000235. weight is 0.030675
loss is 0.000229. weight is 0.030291
loss is 0.000224. weight is 0.029912
loss is 0.000218. weight is 0.029539
loss is 0.000213. weight is 0.029169
loss is 0.000207. weight is 0.028805
loss is 0.000202. weight is 0.028445
loss is 0.000197. weight is 0.028089
loss is 0.000192. weight is 0.027738
loss is 0.000188. weight is 0.027391
loss is 0.000183. weight is 0.027049
loss is 0.000178. weight is 0.026711
loss is 0.000174. weight is 0.026377
loss is 0.000170. weight is 0.026047
loss is 0.000165. weight is 0.025722
loss is 0.000161. weight is 0.025400
loss is 0.000157. weight is 0.025083
loss is 0.000153. weight is 0.024769
loss is 0.000150. weight is 0.024459
loss is 0.000146. weight is 0.024154
loss is 0.000142. weight is 0.023852
loss is 0.000139. weight is 0.023554
loss is 0.000135. weight is 0.023259
loss is 0.000132. weight is 0.022968
loss is 0.000129. weight is 0.022681
loss is 0.000125. weight is 0.022398
loss is 0.000122. weight is 0.022118
loss is 0.000119. weight is 0.021841
loss is 0.000116. weight is 0.021568
loss is 0.000113. weight is 0.021299
loss is 0.000111. weight is 0.021033
loss is 0.000108. weight is 0.020770
loss is 0.000105. weight is 0.020510
loss is 0.000103. weight is 0.020254
loss is 0.000100. weight is 0.020000
loss is 0.000098. weight is 0.019750
loss is 0.000095. weight is 0.019504
loss is 0.000093. weight is 0.019260
loss is 0.000090. weight is 0.019019
loss is 0.000088. weight is 0.018781
loss is 0.000086. weight is 0.018547
loss is 0.000084. weight is 0.018315
loss is 0.000082. weight is 0.018086
loss is 0.000080. weight is 0.017860
loss is 0.000078. weight is 0.017636
loss is 0.000076. weight is 0.017416
loss is 0.000074. weight is 0.017198
loss is 0.000072. weight is 0.016983
loss is 0.000070. weight is 0.016771
loss is 0.000069. weight is 0.016561
loss is 0.000067. weight is 0.016354
loss is 0.000065. weight is 0.016150
loss is 0.000064. weight is 0.015948
loss is 0.000062. weight is 0.015749
loss is 0.000060. weight is 0.015552
loss is 0.000059. weight is 0.015357
loss is 0.000057. weight is 0.015165
loss is 0.000056. weight is 0.014976
loss is 0.000055. weight is 0.014789
loss is 0.000053. weight is 0.014604
loss is 0.000052. weight is 0.014421
loss is 0.000051. weight is 0.014241
loss is 0.000049. weight is 0.014063
loss is 0.000048. weight is 0.013887
loss is 0.000047. weight is 0.013714
loss is 0.000046. weight is 0.013542
loss is 0.000045. weight is 0.013373
loss is 0.000044. weight is 0.013206
loss is 0.000043. weight is 0.013041
loss is 0.000041. weight is 0.012878
loss is 0.000040. weight is 0.012717
loss is 0.000039. weight is 0.012558
loss is 0.000038. weight is 0.012401
loss is 0.000037. weight is 0.012246
loss is 0.000037. weight is 0.012093
loss is 0.000036. weight is 0.011942
loss is 0.000035. weight is 0.011792
loss is 0.000034. weight is 0.011645
loss is 0.000033. weight is 0.011499
loss is 0.000032. weight is 0.011356
loss is 0.000031. weight is 0.011214
loss is 0.000031. weight is 0.011073
loss is 0.000030. weight is 0.010935
loss is 0.000029. weight is 0.010798
loss is 0.000028. weight is 0.010663
loss is 0.000028. weight is 0.010530
loss is 0.000027. weight is 0.010398
loss is 0.000026. weight is 0.010268
loss is 0.000026. weight is 0.010140
loss is 0.000025. weight is 0.010013
loss is 0.000024. weight is 0.009888
loss is 0.000024. weight is 0.009765
loss is 0.000023. weight is 0.009643
loss is 0.000023. weight is 0.009522
loss is 0.000022. weight is 0.009403
loss is 0.000022. weight is 0.009285
loss is 0.000021. weight is 0.009169
loss is 0.000020. weight is 0.009055
loss is 0.000020. weight is 0.008942
loss is 0.000019. weight is 0.008830
loss is 0.000019. weight is 0.008719
loss is 0.000019. weight is 0.008610
loss is 0.000018. weight is 0.008503
loss is 0.000018. weight is 0.008397
loss is 0.000017. weight is 0.008292
loss is 0.000017. weight is 0.008188
loss is 0.000016. weight is 0.008086
loss is 0.000016. weight is 0.007985
loss is 0.000016. weight is 0.007885
loss is 0.000015. weight is 0.007786
loss is 0.000015. weight is 0.007689
loss is 0.000014. weight is 0.007593
loss is 0.000014. weight is 0.007498
loss is 0.000014. weight is 0.007404
loss is 0.000013. weight is 0.007312
loss is 0.000013. weight is 0.007220
loss is 0.000013. weight is 0.007130
loss is 0.000012. weight is 0.007041
loss is 0.000012. weight is 0.006953
loss is 0.000012. weight is 0.006866
loss is 0.000011. weight is 0.006780
loss is 0.000011. weight is 0.006695
loss is 0.000011. weight is 0.006612
loss is 0.000011. weight is 0.006529
loss is 0.000010. weight is 0.006447
loss is 0.000010. weight is 0.006367
loss is 0.000010. weight is 0.006287
loss is 0.000010. weight is 0.006209
loss is 0.000009. weight is 0.006131
loss is 0.000009. weight is 0.006054
loss is 0.000009. weight is 0.005979
loss is 0.000009. weight is 0.005904
loss is 0.000008. weight is 0.005830
loss is 0.000008. weight is 0.005757
loss is 0.000008. weight is 0.005685
loss is 0.000008. weight is 0.005614
loss is 0.000008. weight is 0.005544
loss is 0.000007. weight is 0.005475
loss is 0.000007. weight is 0.005406
loss is 0.000007. weight is 0.005339
loss is 0.000007. weight is 0.005272
loss is 0.000007. weight is 0.005206
loss is 0.000007. weight is 0.005141
loss is 0.000006. weight is 0.005077
loss is 0.000006. weight is 0.005013
loss is 0.000006. weight is 0.004951
loss is 0.000006. weight is 0.004889
loss is 0.000006. weight is 0.004828
loss is 0.000006. weight is 0.004767
loss is 0.000006. weight is 0.004708
loss is 0.000005. weight is 0.004649
loss is 0.000005. weight is 0.004591
loss is 0.000005. weight is 0.004533
loss is 0.000005. weight is 0.004477
loss is 0.000005. weight is 0.004421
loss is 0.000005. weight is 0.004365
loss is 0.000005. weight is 0.004311
loss is 0.000005. weight is 0.004257
loss is 0.000004. weight is 0.004204
loss is 0.000004. weight is 0.004151
loss is 0.000004. weight is 0.004099
loss is 0.000004. weight is 0.004048
loss is 0.000004. weight is 0.003998
loss is 0.000004. weight is 0.003948
loss is 0.000004. weight is 0.003898
loss is 0.000004. weight is 0.003849
loss is 0.000004. weight is 0.003801
loss is 0.000004. weight is 0.003754
loss is 0.000003. weight is 0.003707
loss is 0.000003. weight is 0.003661
loss is 0.000003. weight is 0.003615
loss is 0.000003. weight is 0.003570
loss is 0.000003. weight is 0.003525
loss is 0.000003. weight is 0.003481
loss is 0.000003. weight is 0.003437
loss is 0.000003. weight is 0.003394
loss is 0.000003. weight is 0.003352
loss is 0.000003. weight is 0.003310
loss is 0.000003. weight is 0.003269
loss is 0.000003. weight is 0.003228
loss is 0.000003. weight is 0.003188
loss is 0.000002. weight is 0.003148
loss is 0.000002. weight is 0.003108
loss is 0.000002. weight is 0.003070
loss is 0.000002. weight is 0.003031
loss is 0.000002. weight is 0.002993
loss is 0.000002. weight is 0.002956
loss is 0.000002. weight is 0.002919
loss is 0.000002. weight is 0.002882
loss is 0.000002. weight is 0.002846
loss is 0.000002. weight is 0.002811
loss is 0.000002. weight is 0.002776
loss is 0.000002. weight is 0.002741
loss is 0.000002. weight is 0.002707
loss is 0.000002. weight is 0.002673
loss is 0.000002. weight is 0.002639
loss is 0.000002. weight is 0.002606
loss is 0.000002. weight is 0.002574
loss is 0.000002. weight is 0.002542
loss is 0.000002. weight is 0.002510
loss is 0.000002. weight is 0.002479
loss is 0.000001. weight is 0.002448
loss is 0.000001. weight is 0.002417
loss is 0.000001. weight is 0.002387
loss is 0.000001. weight is 0.002357
loss is 0.000001. weight is 0.002327
loss is 0.000001. weight is 0.002298
loss is 0.000001. weight is 0.002270
loss is 0.000001. weight is 0.002241
loss is 0.000001. weight is 0.002213
loss is 0.000001. weight is 0.002186
loss is 0.000001. weight is 0.002158
loss is 0.000001. weight is 0.002131
loss is 0.000001. weight is 0.002105
loss is 0.000001. weight is 0.002078
loss is 0.000001. weight is 0.002052
loss is 0.000001. weight is 0.002027
loss is 0.000001. weight is 0.002001
loss is 0.000001. weight is 0.001976
loss is 0.000001. weight is 0.001952
loss is 0.000001. weight is 0.001927
loss is 0.000001. weight is 0.001903
loss is 0.000001. weight is 0.001879
loss is 0.000001. weight is 0.001856

In [55]:
plt.scatter(scatter_output_x,scatter_output_y)


Out[55]:
<matplotlib.collections.PathCollection at 0x7fb62075b5c0>

running '$tensorboard --logdir= log_simple_stats' will triger tensorboard


In [ ]: